﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;

namespace KillMasterLu
{
   
    class SysInfoMonitor
    {
        public string GetTher()
        {
            Double CPUtprt = 0;
            string str;
            try
            {

                ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * From MSAcpi_ThermalZoneTemperature");
                foreach (System.Management.ManagementObject mo in mos.Get())
                {
                    CPUtprt = Convert.ToDouble(Convert.ToDouble(mo.GetPropertyValue("CurrentTemperature").ToString()) - 2732) / 10;
                }
            }
            catch (Exception exc)
            {
            }
            str = "CPU 溫度 : " + CPUtprt.ToString() + " °C";
            return str;
        }
        //private readonly Computer computer;
       
        public SysInfoMonitor()
        {
            //computer = new Computer();
            //computer.Open();
            //computer.IsCpuEnabled = true;
            //computer.IsGpuEnabled = true;
        }
        //public IReadOnlyDictionary<string, float> GetSystemInfo()
        // {
        //    var coreAndTemperature = new Dictionary<string, float>();
        //    //UpdateVisitor updateVisitor = new UpdateVisitor();
        //    //computer.Accept(updateVisitor);
        //    foreach (var hardware in computer.Hardware)
        //    {
        //        hardware.Update(); //use hardware.Name to get CPU model
        //        foreach (var sensor in hardware.Sensors)
        //        {
        //            if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
        //                coreAndTemperature.Add(sensor.Name, sensor.Value.Value);
        //        }
        //    }
        //    return coreAndTemperature;
        //}
        public void Dispose()
        {
            try
            {
                //computer.Close();
            }
            catch (Exception)
            {
                //ignore closing errors
            }
        }
    }
}


//internal sealed class CpuTemperatureReader : IDisposable
//{
//    private readonly Computer _computer;

//    public CpuTemperatureReader()
//    {
//        _computer = new Computer { CPUEnabled = true };
//        _computer.Open();
//    }

//    public IReadOnlyDictionary<string, float> GetTemperaturesInCelsius()
//    {
//        var coreAndTemperature = new Dictionary<string, float>();

//        foreach (var hardware in _computer.Hardware)
//        {
//            hardware.Update(); //use hardware.Name to get CPU model
//            foreach (var sensor in hardware.Sensors)
//            {
//                if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
//                    coreAndTemperature.Add(sensor.Name, sensor.Value.Value);
//            }
//        }

//        return coreAndTemperature;
//    }

//    public void Dispose()
//    {
//        try
//        {
//            _computer.Close();
//        }
//        catch (Exception)
//        {
//            //ignore closing errors
//        }
//    }
//}